<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class User_Change_Pw2 extends Page
{
       public $hfNewLength = null;
       public $hfVerLength = null;
       public $JSCompare = null;
       public $Image1 = null;
       public $edVerifyPw = null;
       public $edNewPw = null;
       public $lblError = null;
       public $lblPasswordError = null;
       public $edOldPw = null;
       public $Label8 = null;
       public $Label9 = null;
       public $Label10 = null;
       public $hiddenUser = null;
       public $Button2 = null;
       public $Button1 = null;
       function Button2Click($sender, $params)
       {
       echo '<script language=javascript>
       window.close()</script>';


       }

       function Button1Click($sender, $params)
       {

       $result_account = mysql_query("select * from accounts_tbl where auto_id='".$this->hiddenUser->getValue()."'") or die('SELECT ACCOUNTS'.mysql_error());
       $row_account = mysql_fetch_array($result_account);

       $pw = $row_account['password'];
       $password = sha1($this->edOldPw->getText());
       $newpw = $this->edNewPw->getText();
       $verifypw = $this->edVerifyPw->getText();
       if($pw==$password)
       {
       if($this->edNewPw->Text=='')
       {
       $this->edNewPw->Text='1234';
       $this->edVerifyPw->Text='1234';
       }
       else
       {
       $this->edNewPw->Text;
       }

       if($newpw==$verifypw)
       {
       $query_update_account = "update accounts_tbl set
       password='".sha1($this->edNewPw->Text)."'
       where auto_id='".$this->hiddenUser->getValue()."'";
       mysql_query($query_update_account) or die(mysql_error());

       echo '<script language=javascript>
       alert("Changed Password Successfully!")
       window.close()</script>';
       }
       else
       {
       $this->lblError->Caption='New Passwords did not match';
       }
       }
       else
       {
       $this->lblPasswordError->Caption='Incorrect Old Password';
       }



       }

       function User_Change_Pw2Create($sender, $params)
       {
       $user=$_GET['user'];
       $this->hiddenUser->setValue($user);

       $this->edVerifyPw->Text='';
       $this->edNewPw->Text='';
       $this->edOldPw->Text='';
       $this->lblError->Caption='';
       $this->lblPasswordError->Caption='';
       }

}

global $application;

global $User_Change_Pw2;

//Creates the form
$User_Change_Pw2=new User_Change_Pw2($application);

//Read from resource file
$User_Change_Pw2->loadResource(__FILE__);

//Shows the form
$User_Change_Pw2->show();

?>